package com.zysd.collection.scheduler.controller;

import com.lensyn.common.utils.system.response.Response;
import com.zysd.collection.scheduler.service.model.SchedulerModelTaskService;
import com.zysd.collection.scheduler.service.model.SchedulerTaskModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 任务模板 定时任务 Controller
 *
 * @author liuht
 * @date 2017/10/19 14:17
 */

@RestController
@RequestMapping("/scheduler")
public class SchedulerModelTaskController {

    @Autowired
    private SchedulerTaskModelService modelService;

    @Autowired
    private SchedulerModelTaskService modelTaskService;

    /**
     * 根据模板启动定时任务
     *
     * @param id 模板主键
     * @return 调用结果
     */
    @RequestMapping(value = "/task/{id}/start", method = RequestMethod.POST)
    public Response startModelTask(@PathVariable Long id) {
        modelTaskService.startModelTask(modelService.getById(id));
        return new Response().success();
    }

    /**
     * 根据模板停止定时任务
     *
     * @param id 模板主键
     * @return 调用结果
     */
    @RequestMapping(value = "/task/{id}/stop", method = RequestMethod.POST)
    public Response stopModelTask(@PathVariable Long id) {
        modelTaskService.stopModelTask(modelService.getById(id));
        return new Response().success();
    }

    /**
     * 根据模板删除定时任务
     *
     * @param id 模板主键
     * @return 调用结果
     */
    @RequestMapping(value = "/task/{id}/delete", method = RequestMethod.POST)
    public Response deleteModelTask(@PathVariable Long id) {
        modelTaskService.deleteModelTask(modelService.getById(id));
        return new Response().success();
    }
}
